package b4.model.vo.player
{
	import b4.config.Config;
	import b4.config.LayerConfig;
	import b4.config.TownConfig;
	
	public class Town
	{
		public var townIndex:int;
		public var layerId:int;
		public var myRoleId:int;
		public var roleList:Object;
		public var itemStatus:Object;
		
		public function Town()
		{
			townIndex = -1;
			layerId = -1;
			myRoleId = -1;
			roleList = new Object();
			itemStatus = new Object();
		}
		
		public function getCurrentLayerConfig():LayerConfig
		{
			var townConfig:TownConfig = Config.townConfigs[townIndex];
			return townConfig != null ? townConfig.layers[layerId] : null;
		}
		
		public function containsRole(role:Role):Boolean
		{
			return roleList[role.id] != null; 
		}
		        
		public function addRole(role:Role):void
		{
			roleList[role.id] = role;
		}
		
		public function removeRole(role:Role):void
		{
			if (containsRole(role))
			{
				delete roleList[role.id];
			} 
		}
		
		public function clearOtherRoles():void
		{
			if (myRole != null)
			{
				var role:Role = myRole;
				roleList = new Object();
				roleList[role.id] = role;
			}
			else
			{
				roleList = new Object();
			}
		}
		
        public function get myRole():Role
        {
        	return getRoleById(myRoleId);
        }
        
        public function getRoleById(id:int):Role
        {
        	return roleList[id];
        }
        
	}
}